﻿// *----------------------------------------------------------------
// Copyright (C) 2017 通通优品
// 版权所有。
// 
// 类名：SqlServerDbProviderFactory.cs
// 功能描述：TongTongMall.MallWeb.DapperFramework
// 
// Create User：jym 2017/02/09
// 
// Edit User：UserName,EditTime
// Describe：Describe
// ----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TongTongMall.Dapper;
using TongTongMall.Domain.Uow;

namespace TongTongMall.DapperFramework
{

    public class SqlServerDbProviderFactory : IDbProviderFactory
    {

        private readonly IConnectionStringResolver _connectionStringResolver;
        public SqlServerDbProviderFactory(IConnectionStringResolver connectionStringResolver)
        {
            _connectionStringResolver = connectionStringResolver;
        }

        public string ConnectionString
        {
            get
            {
                var connectionString = _connectionStringResolver.GetNameOrConnectionString();
                return ConfigurationManager.ConnectionStrings[connectionString]?.ConnectionString ?? connectionString;
            }
        }

        public DbProviderFactory DbFactory
        {
            get
            {
                return SqlClientFactory.Instance;
            }
        }
    }
}
